package risk.control.application.component.currency;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import risk.control.application.R;
import risk.control.application.activity.major.WithdrawalBean;
import risk.control.application.entity.CurrencyTypeBean;
import risk.control.application.utils.ViewHolderUtils;

/**
 * 取款方式适配器
 */
public class CurrencyAdapter extends BaseAdapter {

    private final Context mActivity;
    private List<CurrencyTypeBean> mGradeList;

    public CurrencyAdapter(Context context, List<CurrencyTypeBean> gradeList) {
        this.mActivity = context;
        this.mGradeList = gradeList;
    }

    public void refreshData(List<CurrencyTypeBean> gradeList) {
        this.mGradeList = gradeList;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mGradeList == null ? 0 : mGradeList.size();
    }

    @Override
    public CurrencyTypeBean getItem(int position) {
        return mGradeList == null ? null : mGradeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CurrencyTypeBean bean = mGradeList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mActivity).inflate(R.layout.adapter_item_currency, null);
        }
        TextView tvLabel = ViewHolderUtils.get(convertView, R.id.tv_label);
        ImageView ivIcon = ViewHolderUtils.get(convertView, R.id.iv_icon);

        tvLabel.setText(bean.currencyType);
        String isSelect = bean.isSelect;
        if (isSelect.equals("0")) {
            tvLabel.setTextColor(Color.parseColor("#1677ff"));
            ivIcon.setBackgroundResource(R.drawable.switch_on);
        } else {
            tvLabel.setTextColor(Color.parseColor("#8c8c8c"));
            ivIcon.setBackgroundResource(R.drawable.switch_off);
        }
        return convertView;
    }
}
